import Field from "winged/utils/wt-model-field";
import gender from "../../../Resources/utils/wt-form-utils";
import permission from "winged/utils/wt-permission.js";
import request from "winged/utils/axios";
export default {
	title: "用户信息",
	name: "userInfo",
	query: {
		method: "DRONE",
		url: "evaluation/user_info/get_patient_info",
		transfer: true,
		extraParams: ["user_id", "patient_id"],
		placeholder: "当前没有用户记录"
		// tableName: 'patient_info',
	},
	fields: [
		{
			label: "姓名",
			type: Field.types.textarea,
			display: true,
			name: "name",
			tableName: "name"
		},
		{
			label: "会员等级",
			type: Field.types.text,
			display: true,
			name: "bmi_grade",
			tableName: "bmi_grade",
			minWidth: "100px",
			customDisplayComponent: "wt-patient-class"
		},
		{
			label: "身份证",
			type: Field.types.text,
			display: true,
			name: "idcard",
			tableName: "idcard"
		},
		{
			label: "是否已门诊就诊",
			type: Field.types.text,
			display: true,
			name: "isVisitedClinic",
			tableName: "isVisitedClinic",
			customDisplayComponent: "ask-to-confirm",
			customDisplayComponentParams: {
				init: function() {
					console.log("data", this);
					this.value =
						this.data.is_visited == "0" ? "未就诊" : "已就诊";
					this.btn.display = this.data.is_visited == "0";
				},
				value: "未就诊",
				btn: {
					text: "确认患者已就诊",
					loading: false,
					display: true,
					handler: function() {
						this.$confirm(
							"此操作将不可逆转，点击确定继续",
							"确认患者已就诊",
							{
								confirmButtonText: "确定",
								cancelButtonText: "取消",
								type: "warning"
							}
						).then(() => {
							let obj = this.cusComponent;
							console.log("obj", obj);
							obj.btn.loading = true;
							obj.data.is_visited = "1";
							request(
								"uaa/user_info/update_family_patient",
								"DRONE",
								obj.data,
								true,
								response => {
									if (typeof response == "string") {
										response = JSON.parse(response);
									}
									obj.btn.display = false;
									obj.value = "已就诊";
									obj.btn.loading = false;
									this.$message("更新成功！");
								},
								err => {
									obj.btn.loading = false;
									this.$message("操作失敗");
								},
								false
							);
						});
					}
				}
			}
		},
		{
			label: "是否已手术",
			type: Field.types.text,
			display: true,
			name: "hasOperated",
			tableName: "hasOperated",
			customDisplayComponent: "ask-to-confirm",
			customDisplayComponentParams: {
				init: function() {
					//this指代整个customDisplayComponentParams对象
					this.value = this.data.is_operated == "0" ? "否" : "是";
					this.btn.display = this.data.is_operated == "0";
				},
				value: "否",
				btn: {
					text: "确认患者已进行手术",
					loading: false,
					display: true,
					handler: function(obj) {
						//this指代customDisplayComponent组件
						this.$confirm(
							"此操作将不可逆转，点击确定继续",
							"确认患者已进行手术？",
							{
								confirmButtonText: "确定",
								cancelButtonText: "取消",
								type: "warning"
							}
						).then(() => {
							let obj = this.cusComponent;
							obj.btn.loading = true;
							obj.data.is_operated = "1";
							request(
								"uaa/user_info/update_family_patient",
								"DRONE",
								obj.data,
								true,
								response => {
									if (typeof response == "string") {
										response = JSON.parse(response);
									}
									obj.btn.display = false;
									obj.btn.loading = false;
									obj.value = "是";
									this.$message("更新成功！");
									setTimeout(_ => {
										this.$message(
											"会员等级已更新为金色会员"
										);
									}, 1000);
									obj.data.bmi_grade = "金色";
								},
								err => {
									obj.btn.loading = false;
									this.$message("操作失敗");
								},
								false
							);
						});
					}
				}
			}
		},
		{
			label: "性别",
			type: Field.types.number,
			display: true,
			name: "sex",
			tableName: "sex",
			builder: function(data) {
				data[this.tableName] = gender.formatGender(
					data[this.tableName]
				);
			}
		},
		{
			label: "电话",
			type: Field.types.number,
			display: true,
			name: "phone",
			tableName: "phone"
		},
		{
			label: "年龄",
			type: Field.types.number,
			display: true,
			unit: "岁",
			name: "age",
			tableName: "age"
		},
		{
			label: "身高",
			type: Field.types.number,
			unit: "cm",
			display: true,
			name: "height",
			tableName: "height"
		},
		{
			label: "体重",
			type: Field.types.number,
			unit: "kg",
			display: true,
			name: "weight",
			tableName: "weight"
		} /*,{
			label: '学历',
			type: Field.types.text,
			display: true,
			name: 'education',
			tableName: 'education'
		},{
			label: '工作性质',
			type: Field.types.text,
			display: true,
			name: 'job_description',
			tableName: 'job_description'
		},{
			label: '既往病史',
			type: Field.types.text,
			display: true,
			name: 'ill_history',
			tableName: 'ill_history'
		},{
			label: '家族史',
			type: Field.types.text,
			display: true,
			name: 'family_ill_history',
			tableName: 'family_ill_history'
		},{
			label: '地址',
			type: Field.types.textarea,
			display: true,
			summary: true,
			name: 'address',
			tableName: 'address'
		}*/
	]
};
